import React from 'react';

function UseRefCount(props) {

    const [count, setCount] = React.useState(0)

    // 创建一个Ref
    const inputRef = React.useRef();

    const add = () => {
        const value = inputRef.current.value;
        setCount(count + parseInt(value))
    }

    return (
        <div>
            <h2>当前点赞数={count}</h2>
            <input ref={inputRef} defaultValue={1}/>
            <button onClick={add}>点赞</button>
        </div>
    );
}

export default UseRefCount;
